package com.sunzr0119.conventioncentertemplatebackend.controller;

import com.sunzr0119.conventioncentertemplatebackend.dto.UserLoginDTO;
import com.sunzr0119.conventioncentertemplatebackend.dto.UserRegisterDTO;
import com.sunzr0119.conventioncentertemplatebackend.entity.User;
import com.sunzr0119.conventioncentertemplatebackend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user-api")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public ResponseEntity<String> register(@RequestBody UserRegisterDTO userRegisterDTO) {
        return userService.register(userRegisterDTO);
    }

    @PostMapping("/login")
    public ResponseEntity<User> login(@RequestBody UserLoginDTO loginDTO) {
        return userService.login(loginDTO);
    }

//    @PostMapping("/api/user/update-password")
//    public ResponseEntity<?> updatePassword(@RequestBody PasswordRequest request) {
//        if (!userService.verifyPassword(request.getOldPassword())) {
//            return ResponseEntity.badRequest().body(Map.of("success", false, "message", "旧密码错误"));
//        }
//        userService.updatePassword(request.getNewPassword());
//        return ResponseEntity.ok(Map.of("success", true, "message", "密码修改成功"));
//    }

}
